package br.com.felix.fwt.ui;

import java.io.PrintWriter;

import org.apache.log4j.Logger;

import br.com.felix.fwt.log.LoggerFactory;
import br.com.felix.fwt.ui.exception.ComponentRenderException;



/**
 * The Class TextBox implements the HTML input type=text.
 * The name attribute must be set if you want to retrieve the value (inputted by the user) after
 * a form submit.
 */
public class TextBox extends Input{
	
	private static final long serialVersionUID = -2184425294751903314L;

	private static Logger logger = LoggerFactory.getLogger(TextBox.class);
	
	{
		this.cssClass = "fwttextbox";
	}
	
	/**
	 * Instantiates a new text box with null name and value.
	 */
	public TextBox() {
		super();
	}
	
	/**
     * Instantiates a new text box.
     * 
     * @param value the value
     */
    public TextBox(String value) {
        super(value);
    }

	/* (non-Javadoc)
	 * @see br.com.felix.fwt.ui.Input#write(java.io.PrintWriter)
	 */
	@Override
	public void write(PrintWriter out) throws ComponentRenderException {
		if(!authorized()) return;
		PresentationMode pMode = getPresentationMode();
		String value = getValue();
		switch(pMode){
			case EDIT:
				out.write("\n<input type=\"text\"");
				out.write(" name=\"");
				out.write(getName());
				out.write("\" value=\"");
				if(value!=null)out.write(value);
				out.write("\"");
				if(style!=null)out.write(style);
				out.write(" />");
				break;
			case SHOW:
				out.write(value);
				break;
			case DELETED:
				out.write("\n<del>");
				out.write(value);
				out.write("</del>");
		}
	}

	
}
